Skip to content

Instantly share code, notes, and snippets.

@ivar
Last active August 29, 2015 14:03
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 ivar/1132a2cb6a9e84ad6576 to your computer and use it in GitHub Desktop.
Save ivar/1132a2cb6a9e84ad6576 to your computer and use it in GitHub Desktop.
Automated query to load table structure from Rspec and Rails does not recognize "properties_view" as a valid 'table'.
SELECT a.attname, format_type(a.atttypid, a.atttypmod),
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"properties_view"'::regclass # NOTE properties_view is a view on properties table
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum;
SELECT a.attname, format_type(a.atttypid, a.atttypmod),
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"properties"'::regclass # NOTE properties is a normal table
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum;
@ivar
Copy link
Author

ivar commented Jul 9, 2014

Note 'properties_view' is a view that selects a subset of data from the 'properties' table

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment