Skip to content

Instantly share code, notes, and snippets.

@peterbe
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterbe/9004593 to your computer and use it in GitHub Desktop.
Save peterbe/9004593 to your computer and use it in GitHub Desktop.
WITH
update_graphics_device AS (
UPDATE graphics_device
SET
adapter_name = 'Unknown Webcam Pro 9000',
vendor_name = 'Logitech Inc.'
WHERE
vendor_hex = '0x1002'
AND
adapter_hex = '0x0166'
RETURNING 1
),
insert_graphics_device AS (
INSERT INTO
graphics_device
(vendor_hex, adapter_hex, vendor_name, adapter_name)
SELECT
'0x1002' AS vendor_hex,
'0x0166' AS adapter_hex,
'Logitech Inc.' AS vendor_name,
'Unknown Webcam Pro 9000' AS adapter_name
WHERE NOT EXISTS (
SELECT * FROM graphics_device
WHERE
vendor_hex = '0x1002'
AND
adapter_hex = '0x0166'
LIMIT 1
)
RETURNING 2
)
SELECT * FROM update_graphics_device UNION ALL SELECT * FROM insert_graphics_device;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment